# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import pymongo
from scrapy.conf import settings


class BossPipeline(object):
    def process_item(self, item, spider):
        return item


class JobPipeline(object):

    def __init__(self):
        host = settings['MONGODB_HOST']
        port = settings['MONGODB_PORT']
        dbname = settings['MONGODB_NAME']
        sheetname = settings['MONGODB_SHEETNAME']
        # 数据库连接客户端
        client = pymongo.MongoClient(host=host, port=port)
        # 数据库
        db = client[dbname]
        # 数据表
        self.col = db[sheetname]
    
    def process_item(self, item, spider):
        data = dict(item)
        self.col.insert(data)
        print("========================")
        return data
        # pass